/**
 * 使用方法：
 *
 */

import { BaseAnalysis, AnalysisContext } from './BaseAnalysis';

export enum AnalysisType {
  Profile = 'Profile',
  Viewshed = 'Viewshed',
  Contour = 'Contour',
  Flood = 'Flood',
  Skyline = 'Skyline',
  Sun = 'Sun',
  Sightline = 'Sightline',
  Shadow = 'Shadow',
}

export class AnalysisTools {
  private context: AnalysisContext;
  private analysisMap: Map<AnalysisType, BaseAnalysis> = new Map();

  constructor(ctx: AnalysisContext) {
    this.context = ctx;
  }

  public async activate(type: AnalysisType): Promise<void> {
    this.clearAll();
    if (!this.analysisMap.has(type)) {
      const module = await import(`./impl/${type}Analysis`);
      const AnalysisClass = module[`${type}Analysis`];
      const instance = new AnalysisClass(this.context);
      this.analysisMap.set(type, instance);
    }
    this.analysisMap.get(type)?.activate();
  }

  public clearAll(): void {
    this.analysisMap.forEach((a) => a.clear());
  }
}
